package org.lambda.list;

import com.alibaba.fastjson.JSON;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ListDemo {

    private static final int SIZE = 10;

    public static void main(String[] args) {
        Supplier<Integer> supplier = () -> new Random().nextInt(10);

        List<Integer> list = new ArrayList<Integer>(10) {
            private static final long serialVersionUID = -2717645279176492338L;
            {
                for (int i = 0; i < SIZE; i++) {
                    add(supplier.get());
                }
            }
        };

        list.stream().forEach(System.out::print);
        System.out.println("\n--------");

        list.stream().sorted().collect(Collectors.toList()).forEach(System.out::print);
        System.out.println("\n--------");
        list.stream().sorted((k1, k2) -> k1 - k2).collect(Collectors.toList()).forEach(System.out::print);
        System.out.println("\n--------");
        list.stream().sorted((k1, k2) -> k2 - k1).collect(Collectors.toList()).forEach(System.out::print);
        System.out.println("\n--------");

        list.stream().filter((i) -> i > 3).collect(Collectors.toList()).forEach(System.out::print);
        System.out.println("\n--------");

        System.out.print(list.stream().count());
        System.out.println("\n--------");

        System.out.print(list.stream().max((v1, v2) -> v1 - v2).get());
        System.out.println("\n--------");
        System.out.print(list.stream().min((v1, v2) -> v1 - v2).get());
        System.out.println("\n--------");

        list.stream().forEach((value) -> System.out.println(MessageFormat.format("value:{0},index:{1}", value, list.indexOf(value))));
        System.out.println("--------");
    }
}
